package com.hmall.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hdmall.business.common.common.ServerResponse;
import com.hmall.mapper.MallBannerMapper;
import com.hmall.model.MallBanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MallBannerService {
    private final
    MallBannerMapper mallBannerMapper;

    @Autowired
    public MallBannerService(MallBannerMapper mallBannerMapper) {
        this.mallBannerMapper = mallBannerMapper;
    }

    public ServerResponse<PageInfo<MallBanner>> getProductList(int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<MallBanner> bannerList = mallBannerMapper.selectList();
        PageInfo<MallBanner> pageResult = new PageInfo<>(bannerList);
        return ServerResponse.createBySuccess(pageResult);
    }

    public ServerResponse<PageInfo<MallBanner>> searchBanner(String query, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<MallBanner> bannerList = mallBannerMapper.selectListByName(query);
        PageInfo<MallBanner> pageResult = new PageInfo<>(bannerList);
        return ServerResponse.createBySuccess(pageResult);
    }
}
